package contegor.scire.core.modifications;

import contegor.scire.core.Connectable;
import contegor.scire.core.Container;
import contegor.scire.core.Id;
import contegor.scire.core.Modifiable;
import contegor.scire.core.Task;
import contegor.scire.core.TaskImpl;
import contegor.scire.core.Version;


/**
 * Base class for all the updates that can be issued to a {@link Container}. Implements the {@link Task} interface
 * and are executed over a {@link Modifiable}. 
 *
 * @version $Revision: 1.3 $
 * @author  Héctor Cirbián Pousa ($Author: hector $)
 */
@Version("$Id: Modification.java,v 1.3 2010-02-01 10:55:40 hector Exp $")
public abstract class Modification<C extends Connectable> extends TaskImpl<C> {
  private static final long serialVersionUID = -6168614091452562424L;

  protected long relatedTime;

  protected Modification(Id targetContainerId) {
    super(targetContainerId);
    this.relatedTime = System.currentTimeMillis();
  }

  public void setRelatedTime(long time) {
    this.relatedTime = time;
  }

  protected boolean isValidForThisContainer(Container targetContainer) {
    return (targetContainer instanceof Modifiable) && (returnPoint != null) && (targetContainer.getId().equals(this.targetContainerId));
  }

  /** Number of 'steps' needed to reach the target element. The default is one. */
  public int getDepth() {
    return 1;
  }
}